package com.ctshk.sapp.order.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.hotel.dto.HotelOrderDetailDTO;
import com.ctshk.rpc.order.hotel.dto.HotelOrderPageDTO;
import com.ctshk.rpc.order.hotel.req.HotelApprovalOrderReq;
import com.ctshk.rpc.order.hotel.req.HotelCancelOrderReq;
import com.ctshk.rpc.order.hotel.req.HotelOrderPageReq;
import com.ctshk.rpc.order.hotel.req.HotelOrderTouristReq;
import com.ctshk.rpc.order.hotel.service.IHotelOrderCenterService;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @description 酒店订单表 前端控制器
 * @author 谢诗宏
 * @date 2021/5/10
 */
@Api(value = "酒店订单",tags = "订单中心")
@RestController
@RequestMapping("/center")
public class HotelOrderCenterController extends BaseController {

    @DubboReference
    private IHotelOrderCenterService hotelOrderCenterService;

    @ApiOperation(value="订单列表", notes="酒店订单分页查询列表-酒店订单分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "酒店订单分页查询列表", operDesc = "订单中心-酒店订单分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<HotelOrderPageDTO>> queryBusLineList(@RequestBody HotelOrderPageReq hotelOrderPageReq) {
        PageResponse<HotelOrderPageDTO> response = hotelOrderCenterService.queyList(hotelOrderPageReq, getCurrentUser(getRequest()).getId());
        return Result.success(response);
    }

    @ApiOperation(value="酒店订单详情", notes="酒店订单详情")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "酒店订单详情", operDesc = "订单中心-酒店订单详情")
    @GetMapping("/detail/{id}")
    public Result<HotelOrderDetailDTO> detail(@PathVariable Long id) {
        return Result.success(hotelOrderCenterService.queryDetail(id));
    }

    @ApiOperation(value = "取消订单", notes = "取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "取消订单", operDesc = "订单中心酒店-取消订单")
    @PostMapping(value = "/cancel")
    public Result cancelOrder(@RequestBody HotelCancelOrderReq cancelOrderReq){
        return hotelOrderCenterService.cancelOrder(cancelOrderReq, getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value = "审批退款订单", notes = "审批退款订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "审批退款订单", operDesc = "订单中心酒店-审批退款订单")
    @PostMapping(value = "/refund/approval")
    public Result approval(@RequestBody @Valid HotelApprovalOrderReq req){
        return Result.success(hotelOrderCenterService.check(req.getApprovalId(), getCurrentUser(getRequest()).getId(), req.getStatus(), req.getComments(), req.getExtendParams(), req.getActualRefundAmount()));
    }

    @ApiOperation(value = "删除退款记录", notes = "删除退款记录")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "删除退款记录", operDesc = "订单中心酒店-删除退款记录")
    @GetMapping(value = "/refund/del/{id}")
    @ApiImplicitParam(name = "id", value = "退款记录id", required = true)
    public Result delRefund(@PathVariable Long id){
        return Result.success(hotelOrderCenterService.delRefund(id, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value = "收款再次确认", notes = "收款再次确认")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "删除退款记录", operDesc = "订单中心酒店-删除退款记录")
    @GetMapping(value = "/collection/reconfirm/{id}")
    @ApiImplicitParam(name = "id", value = "收款记录id", required = true)
    public Result reconfirm(@PathVariable Long id){
        return Result.success(hotelOrderCenterService.reconfirm(id, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value = "操作退款", notes = "操作退款-只有退款方式为现金并且审核通过的退款才有操作退款按钮")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "操作退款", operDesc = "订单中心酒店-操作退款")
    @GetMapping(value = "/refund/confirm/{id}")
    @ApiImplicitParam(name = "id", value = "退款记录id", required = true)
    public Result refundConfirm(@PathVariable Long id){
        return Result.success(hotelOrderCenterService.confirmRefund(id, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value = "确认订单", notes = "确认订单-只有外挂单订单并且是门店出票的订单才有确认订单按钮")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "确认订单", operDesc = "订单中心酒店-确认订单")
    @GetMapping(value = "/confirm/{id}/{number}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true),
            @ApiImplicitParam(name = "number", value = "确认单号", required = true)
    })
    public Result confirm(@PathVariable Long id, @PathVariable String number){
        return Result.success(hotelOrderCenterService.confirmOrder(id, number, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value = "退款金额", notes = "退款金额-获取当前订单最大退款金额")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "退款金额", operDesc = "订单中心酒店-退款金额")
    @GetMapping(value = "/refund/amount/{id}")
    @ApiImplicitParam(name = "id", value = "订单id", required = true)
    public Result refundAmount(@PathVariable Long id){
        return Result.success(hotelOrderCenterService.refundAmount(id));
    }

    @ApiOperation(value = "修改旅客", notes = "修改旅客")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "修改旅客", operDesc = "订单中心酒店-修改旅客")
    @PostMapping(value = "/tourist/modify/{id}")
    @ApiImplicitParam(name = "id", value = "订单id", required = true)
    public Result modifyTourist(@PathVariable Long id, @RequestBody List<HotelOrderTouristReq> reqs){
        return Result.success(hotelOrderCenterService.modifyTourist(reqs, id, getCurrentUser().getId()));
    }

}
